package com.zzyd.factory.net.account;

import android.util.Log;

import com.zzyd.common.mvp.data.DataSource;
import com.zzyd.common.utils.key.AESUtils;
import com.zzyd.factory.model.account.Usdfs;
import com.zzyd.factory.model.account.User;
import com.zzyd.factory.net.DataNetApi;
import com.zzyd.factory.net.NetWork;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author wjunjie
 * @version 1.0
 * @E-mail wang_junjie007@163.com
 * @company ZZYD
 * @createTime 2018/7/23 17:12
 * @类注释:
 */
public class AccountDataHelper {
    public static final String KEY = AESUtils.generateKey();

    public static void register() {

    }

    /**
     * 登陆
     * @param map 参数
     * @param callBack retrofit
     */
    public static void login(Map<String,String> map, final DataSource.CallBack<User> callBack) {
        DataNetApi dataNetApi = NetWork.getRetrofit().create(DataNetApi.class);
        Call<User> call = dataNetApi.accountLogin(map);
        call.enqueue(new Callback<User>() {
            @Override
            public void onResponse(Call<User> call, Response<User> response) {

            }

            @Override
            public void onFailure(Call<User> call, Throwable t) {

            }
        });

    }

    public static void forgetPwd(String content,String key) {
        Log.e("content",content);
        Log.e("key",key);
        DataNetApi dataNetApi = NetWork.getRetrofit().create(DataNetApi.class);
        Call<Usdfs> tstres = dataNetApi.tstres(content,key);
        tstres.enqueue(new Callback<Usdfs>() {
            @Override
            public void onResponse(Call<Usdfs> call, Response<Usdfs> response) {
                try {
                    String s = AESUtils.decryptData(KEY,response.body().getName());
                    Log.e("TAG",response.body().getName());
                    Log.e("TAG",s);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onFailure(Call<Usdfs> call, Throwable t) {
                Log.e("TAG",t.getMessage());
            }
        });
    }
}
